<!--
 * @Date: 2020-04-22 10:20:45
 * @LastEditors: 黄栋
 * @LastEditTime: 2020-04-22 15:50:11
 * @FilePath: /cloudAdmin/src/views/market/promotion/member/userIntegral.vue
 -->
<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/promotion' }">会员营销</el-breadcrumb-item>
          <el-breadcrumb-item>积分管理</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-card>
        <el-table :data="list1" size="mini">
          <el-table-column prop="name" label="积分获取"></el-table-column>
          <el-table-column prop="description" label="权益内容"></el-table-column>
          <el-table-column label="操作" align="right">
            <template slot-scope="{row}">
              <el-button v-if="row.name.indexOf('签到')>-1" type="text" @click="setSign(row)">签到设置</el-button>
              <el-button type="text" @click="getdataDetail(row)">权益内容修改</el-button>
             
              <el-switch
                style="margin-left:10px"
                v-model="row.status"
                :active-value="1"
                :inactive-value="2"
                active-text="启用"
                inactive-text="禁用"
                @change="val=>changeStatus(row.id,val)"
              ></el-switch>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <div style="margin-top:10px"></div>
      <el-card>
        <el-table :data="list2" size="mini">
          <el-table-column prop="name" label="积分用途"></el-table-column>
          <el-table-column prop="description" label="权益内容"></el-table-column>
          <el-table-column label="操作" align="right">
            <template slot-scope="{row}">
              <el-button  v-if="row.name.indexOf('抽奖')==-1" type="text" @click="getdataDetail(row)">权益内容修改</el-button>
               <el-button v-if="row.name.indexOf('抽奖')>-1" type="text" @click="$router.push({path:'/userActivity'})">活动管理</el-button>
              <el-switch
                style="margin-left:10px;"
                v-model="row.status"
                :active-value="1"
                :inactive-value="2"
                active-text="启用"
                inactive-text="禁用"
                @change="val=>changeStatus(row.id,val)"
              ></el-switch>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </el-card>
    <moduleDetail v-if="showDetail" ref="detailRef" />
    <singSet v-if="singShow" ref="singRef" />
  </div>
</template>

<script>
import moduleDetail from "./components/moduleDetail";
import singSet from "./components/singSet";
export default {
  components: { moduleDetail, singSet },
  data() {
    return {
      list1: [],
      list2: [],
      showDetail: false,
      singShow: false
    };
  },
  activated() {
    this.getPageData();
  },
  methods: {
    getPageData() {
      this.getdataList(1);
      this.getdataList(2);
    },
    getdataList(type) {
      this.$http({
        url: this.$http.adornUrl("/market/score/get_module_set_list"),
        method: "post",
        data: this.$http.adornData({ type: type })
      }).then(res => {
        console.log(res);
        if (res.code == 200) {
          if (type == 1) {
            this.list1 = res.data;
          } else {
            this.list2 = res.data;
          }
        }
      });
    },
    /**查看详情 */
    getdataDetail(row) {
      this.showDetail = true;
      this.$nextTick(() => {
        this.$refs.detailRef.initData(row.id);
      });
    },
    /**开启/关闭 */
    changeStatus(id, status) {
      this.$http({
        url: this.$http.adornUrl("/market/score/edit_module_set_status"),
        method: "post",
        data: this.$http.adornData({ id: id, status: status })
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            message: res.message,
            type: "success",
            duration: 1000,
            onClose: () => {
              this.getPageData();
            }
          });
        } else {
          this.$message.error(res.message);
        }
      });
    },
    /**签到设置 */
    setSign() {
      this.singShow = true;
      this.$nextTick(() => {
        this.$refs.singRef.initData();
      });
    }
  }
};
</script>

<style>
</style>